nl80211: fix 5Ghz frequency calculations master
authorGeorge Sapkin <george@sapk.in>
Fri, 9 Jan 2026 17:16:52 +0000 (19:16 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Tue, 13 Jan 2026 23:33:03 +0000 (00:33 +0100)
nl80211_channel2freq assumes that if ieee80211ax=1 is set in
/var/run/hostapd-XXX.conf, the channel must be in the 6GHz band. Check
op_class instead, which is between 131 and 137 for 6GHz.

Fixes: 3f619a5fbe10 ("nl80211: fix frequency/channel conversion for the 6G band")
Signed-off-by: George Sapkin <george@sapk.in>
Link: https://github.com/openwrt/iwinfo/pull/31
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
iwinfo_nl80211.c

index 813678a8706ba9315335c4ee0fbb34405e2f8e27..1dd6a67d31004491b2b5b77822f2be6a40786f6b 100644 (file)
@@ -707,7 +707,7 @@ static int nl80211_freq2channel(int freq)
  * Copyright 2017 Intel Deutschland GmbH
  * Copyright (C) 2018-2022 Intel Corporation
  */
-static int nl80211_channel2freq(int channel, const char *band, bool ax)
+static int nl80211_channel2freq(const int channel, const char *band, const int opclass)
 {
        if (channel < 1)
                return 0;
@@ -724,7 +724,8 @@ static int nl80211_channel2freq(int channel, const char *band, bool ax)
                if (channel < 7)
                        return 56160 + 2160 * channel;
        }
-       else if (ax)
+       // 6GHz: opclass between 131 and 137
+       else if (opclass >= 131 && opclass <= 137)
        {
                if (channel == 2)
                        return 5935;
@@ -1492,7 +1493,7 @@ static int nl80211_get_frequency_info_cb(struct nl_msg *msg, void *arg)
 
 static int nl80211_get_frequency(const char *ifname, int *buf)
 {
-       char *res, channel[4] = { 0 }, hwmode[3] = { 0 }, ax[2] = { 0 };
+       char *res, channel[4] = { 0 }, hwmode[3] = { 0 }, opclass[4] = { 0 };
 
        /* try to find frequency from interface info */
        res = nl80211_phy2ifname(ifname);
@@ -1505,9 +1506,9 @@ static int nl80211_get_frequency(const char *ifname, int *buf)
        if ((*buf == 0) &&
            nl80211_hostapd_query(ifname, "hw_mode", hwmode, sizeof(hwmode),
                                          "channel", channel, sizeof(channel),
-                                         "ieee80211ax", ax, sizeof(ax)) >= 2)
+                                         "op_class", opclass, sizeof(opclass)) >= 2)
        {
-               *buf = nl80211_channel2freq(atoi(channel), hwmode, ax[0] == '1');
+               *buf = nl80211_channel2freq(atoi(channel), hwmode, atoi(opclass));
        }
 
        /* failed, try to find frequency from scan results */
@@ -3860,7 +3861,7 @@ const struct iwinfo_ops nl80211_ops = {
        .mbssid_support   = nl80211_get_mbssid_support,
        .hwmodelist       = nl80211_get_hwmodelist,
        .htmodelist       = nl80211_get_htmodelist,
-       .htmode           = nl80211_get_htmode,
+       .htmode           = nl80211_get_htmode,
        .mode             = nl80211_get_mode,
        .ssid             = nl80211_get_ssid,
        .bssid            = nl80211_get_bssid,